<?php
/**
 * @version     1.0.0
 * @package     com_travel
 * @copyright   Copyright (C) 2013. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      thinh <dinhducthinh88@yahoo.com> - http://
 */
// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');
require_once(JPATH_COMPONENT.DS.'models'.DS.'fields.php');
require_once(JPATH_COMPONENT.DS.'models'.DS.'field.php');
require_once(JPATH_COMPONENT.DS.'helpers'.DS.'field.php');
/**
 * View to edit
 */
class TravelViewTour extends JView
{
	protected $state;
	protected $item;
	protected $form;
	
	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
		$this->state	= $this->get('State');
		$this->item		= $this->get('Item');
		$this->form		= $this->get('Form');
		
		$fieldsModel	= new TravelModelFields();
		$fields 		= $fieldsModel->getFields();
		
		$this->assignRef('fields',$fields);
		
		$plugins 		= '';
		$conf			= '';
		$field = new JHTMLTourField($conf,"1",$plugins,"",$this->get('baseurl'));
		$this->assignRef('field',$field);
		
		echo $errorMsg = JRequest::getString('errorMsg','');
		$nullobj = null;
		if ($errorMsg != "")
			$this->assignRef('default',(object) JRequest::get( 'post' ));
		else
			$this->assignRef('default',$nullobj);
		
		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
            throw new Exception(implode("\n", $errors));
		}

		$this->editToolbar();
		parent::display($tpl);
	}
	
	
	protected function editToolbar()
	{
		JRequest::getVar('hidemenu',true);
		
		$user		= JFactory::getUser();
		$userId		= $user->get('id');
		$checkedOut	= !($this->item->checked_out == 0 || $this->item->checked_out == $userId);
		
		if (!$checkedOut) {
			JToolBarHelper::apply('tour.apply');
			JToolBarHelper::save('tour.save');
			JToolBarHelper::save2new('tour.save2new');
		}
		
		JToolBarHelper::title( JText::_('COM_TRAVEL_TITLE'), 'Travel Manager' );
		JToolBarHelper::cancel('tour.cancel');
	}
}